import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/module/team/soccer/zq_team_detail_logic.dart';
import 'package:ball_lion/module/team/soccer/zq_team_lineup_logic.dart';
import 'package:ball_lion/module/team/items/team_value_item.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/widgets/loading/loading_widget.dart';

class SoccerTeamLineupView extends StatefulWidget {
  const SoccerTeamLineupView({super.key, required this.teamId});
  final int teamId;

  @override
  State<SoccerTeamLineupView> createState() => _SoccerTeamLineupViewState();
}

class _SoccerTeamLineupViewState extends State<SoccerTeamLineupView> {
  late final SoccerTeamLineupLogic logic =
      Get.put(SoccerTeamLineupLogic(), tag: widget.teamId.toString());
  late final SoccerTeamDetailLogic teamLogic =
      Get.find<SoccerTeamDetailLogic>(tag: widget.teamId.toString());
  @override
  Widget build(BuildContext context) {
    return GetBuilder<SoccerTeamLineupLogic>(
        initState: (state) => logic.requestData(widget.teamId),
        tag: widget.teamId.toString(),
        builder: (controller) {
          return LoadingWidget<bool>(
            isLoading: controller.isLoading,
            data:
                controller.data.every((element) => element.player?.length == 0),
            child: () => Container(
                color: Colours.N1,
                child: ListView(
                    //physics: const ClampingScrollPhysics(),
                    padding: EdgeInsets.zero,
                    children: List.generate(
                        controller.data.length,
                        (index) => PlayerValueItem(
                            lineup: controller.data[index],
                            detail: teamLogic.data,
                            section: index)))),
          );
        });
  }
}
